package question

import "sort"

// 49. 字母异位词分组
func groupAnagrams(strs []string) [][]string {
	m := make(map[string][]string)
	for _, v := range strs {
		arr := []byte(v)
		sort.Slice(arr, func(i, j int) bool {
			return arr[i] < arr[j]
		})
		s := string(arr)
		m[s] = append(m[s], v)
	}
	res := make([][]string, 0)
	for _, v := range m {
		res = append(res, v)
	}
	return res
}
